package com.sgcc.operate.service.impl;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.sgcc.common.core.domain.R;
import com.sgcc.common.core.web.domain.AjaxResult;
import com.sgcc.common.security.service.TokenService;
import com.sgcc.operate.domain.OIndiContent;
import com.sgcc.operate.mapper.OIndiContentMapper;
import com.sgcc.system.api.RemoteDictDataService;
import com.sgcc.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sgcc.operate.mapper.OSchemeFormMapper;
import com.sgcc.operate.domain.OSchemeForm;
import com.sgcc.operate.service.IOSchemeFormService;

/**
 * 运营方案制定Service业务层处理
 *
 * @author sgcc
 * @date 2021-03-23
 */
@Service
public class OSchemeFormServiceImpl implements IOSchemeFormService {
    @Autowired
    private OSchemeFormMapper oSchemeFormMapper;
    @Autowired
    private TokenService tokenService;
    @Autowired
    private OIndiContentMapper oIndiContentMapper;
    @Autowired
    private RemoteDictDataService remoteDictDataService;

    /**
     * 查询运营方案制定
     *
     * @param id 运营方案制定ID
     * @return 运营方案制定
     */
    @Override
    public OSchemeForm selectOSchemeFormById(String id) {

        OSchemeForm oSchemeForm = oSchemeFormMapper.selectOSchemeFormById(id);
        OIndiContent oIndiContent = new OIndiContent();
        oIndiContent.setSchemeid(id);
        oSchemeForm.setOindiContentList(oIndiContentMapper.selectOIndiContentList(oIndiContent));
        return oSchemeForm;
    }

    /**
     * 查询运营方案制定列表
     *
     * @param oSchemeForm 运营方案制定
     * @return 运营方案制定
     */
    @Override
    public List<OSchemeForm> selectOSchemeFormList(OSchemeForm oSchemeForm) {
        return oSchemeFormMapper.selectOSchemeFormList(oSchemeForm);
    }

    /**
     * 新增运营方案制定
     *
     * @param oSchemeForm 运营方案制定
     * @return 结果
     */
    @Override
    public int insertOSchemeForm(OSchemeForm oSchemeForm) {
        LoginUser loginUser = tokenService.getLoginUser();
        oSchemeForm.setCreateDate(new Date());
        oSchemeForm.setUpdateDate(new Date());
        oSchemeForm.setCreateBy(loginUser.getUserid());
        oSchemeForm.setUpdateBy(loginUser.getUserid());
        oSchemeForm.setModifyorg(loginUser.getSysUser().getDeptId());
        oSchemeForm.setDelFlag("0");
        oSchemeForm.setSchemestatus("01");
        oSchemeForm.setModifyemp(loginUser.getSysUser().getDeptId());
        oSchemeForm.setModifytime(new Date());
        oSchemeForm.setManageorg(oSchemeForm.getModifyorg());
//        R idstr = remoteDictDataService.getIdStr("same_day_id_create", "rule_attr_id");
//        if (idstr.getCode() == 200) {
//            oSchemeForm.setId(idstr.getData() + "");
            return oSchemeFormMapper.insertOSchemeForm(oSchemeForm);
//        }
//        return 0;
    }

    /**
     * 修改运营方案制定
     *
     * @param oSchemeForm 运营方案制定
     * @return 结果
     */
    @Override
    public int updateOSchemeForm(OSchemeForm oSchemeForm) {
        LoginUser loginUser = tokenService.getLoginUser();
        oSchemeForm.setUpdateDate(new Date());
        oSchemeForm.setUpdateBy(loginUser.getUserid());
        oSchemeForm.setModifyorg(loginUser.getSysUser().getDeptId());
        oSchemeForm.setModifyemp(loginUser.getSysUser().getDeptId());
        oSchemeForm.setModifytime(new Date());
        return oSchemeFormMapper.updateOSchemeForm(oSchemeForm);
    }

    /**
     * 批量删除运营方案制定
     *
     * @param ids 需要删除的运营方案制定ID
     * @return 结果
     */
    @Override
    public int deleteOSchemeFormByIds(String[] ids) {
        oSchemeFormMapper.deleteOSchemeFormByIds(ids);
        oIndiContentMapper.deleteOIndiContentByschemeidIds(ids);
        return 1;
    }

    /**
     * 删除运营方案制定信息
     *
     * @param id 运营方案制定ID
     * @return 结果
     */
    @Override
    public int deleteOSchemeFormById(String id) {
        return oSchemeFormMapper.deleteOSchemeFormById(id);
    }

    @Override
    public int deleteOindiContent(OIndiContent oIndiContent) {
        return oIndiContentMapper.deleteOindiContent(oIndiContent);
    }

    @Override
    public List<OSchemeForm> actiListData(OSchemeForm oSchemeForm) {
        return oSchemeFormMapper.configureActiList(oSchemeForm);
    }

    @Override
    public AjaxResult getOSchemeNum() {
        R idstr = remoteDictDataService.getIdStr("same_day_id_create", "rule_attr_id");
        if (idstr.getCode() == 200) {
            return AjaxResult.success("ZBFA"+idstr.getData() );
        }
        return AjaxResult.error("获取失败");
    }
}
